import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
import { getAllRolesListNoByTenant } from './ShipMember.api';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'username',
    width: '80px'
  },
  {
    title: '姓名',
    dataIndex: 'realname',
    width: '60px'

  },
  {
    title: '积分',
    dataIndex: 'point',
    width: '70px',
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    width: '80px'

  },
  {
    title: '等级',
    dataIndex: 'grade_dictText',
    width: '60px'

  }, {
    title: '性别',
    dataIndex: 'sex_dictText',
    width: '60px'

  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "对应账号ID",
    field: 'userId',
    component: 'JSearchSelect',
    componentProps: {
      dict: "sys_user where user_type = 1,realname,id"
    },
    //colProps: {span: 6},
  },
];
export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '用户账号',
    field: 'username',
    component: 'Input',
    required: true,

    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
    // dynamicRules: ({ model, schema }) => rules.duplicateCheckRule('sys_user', 'username', model, schema, true),
  },
  {
    label: '登录密码',
    field: 'password',
    component: 'StrengthMeter',
    componentProps: {
      autocomplete: 'new-password',
    },
    rules: [
      {
        required: true,
        message: '请输入登录密码',
      },
      {
        pattern: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,./]).{8,}$/,
        message: '密码由8位数字、大小写字母和特殊符号组成!',
      },
    ],
  },
  {
    label: '确认密码',
    field: 'confirmPassword',
    component: 'InputPassword',
    dynamicRules: ({ values }) => rules.confirmPassword(values, true),
  },
  {
    label: '用户姓名',
    field: 'realname',
    required: true,
    component: 'Input',
  },
  // {
  //   label: '工号',
  //   field: 'workNo',
  //   required: true,
  //   component: 'Input',
  // },

  // {
  //   label: '角色',
  //   field: 'selectedroles',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     mode: 'multiple',
  //     api: getAllRolesListNoByTenant,
  //     labelField: 'roleName',
  //     valueField: 'id',
  //     immediate: false,
  //   },
  // },


  {
    label: '身份',
    field: 'userIdentity',
    component: 'RadioGroup',
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '普通用户', value: 1, key: '1' },

        ],
        onChange: () => {
          formModel.userIdentity == 1 && (formModel.departIds = []);
        },
      };
    },
  },
  {
    label: '负责部门',
    field: 'departIds',
    component: 'Select',
    componentProps: {
      mode: 'multiple',
    },
    ifShow: ({ values }) => values.userIdentity == 2,
  },
  {
    label: '头像',
    field: 'avatar',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
    },
  },
  {
    label: '生日',
    field: 'birthday',
    component: 'DatePicker',
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'sex',
      placeholder: '请选择性别',
      stringToNumber: true,
    },
  },

  {
    label: '手机号码',
    field: 'phone',
    component: 'Input',
    required: true,
    dynamicRules: ({ model, schema }) => {
      return [
        // { ...rules.duplicateCheckRule('sys_user', 'phone', model, schema, true)[0], trigger: 'blur' },
        { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式有误', trigger: 'blur' },
      ];
    },
  },


];


// 高级查询数据
export const superQuerySchema = {
  name: { title: '用户名称', order: 0, view: 'text', type: 'string', },
  userId: { title: '对应账号ID', order: 1, view: 'sel_search', type: 'string', dictTable: "sys_user where user_type = 1", dictCode: 'id', dictText: 'realname', },
  points: { title: '积分', order: 2, view: 'number', type: 'number', },
  grade: { title: '0普通 1vip 2员工 3领班 4店长 5经理 6总监 7董事', order: 3, view: 'text', type: 'string', },
  phone: { title: '用户手机号', order: 4, view: 'text', type: 'string', },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}